package com.gimi.cloud.bbp.commonService.InterfacePlatform.impl;

import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.exception.MsgException;
import com.gimi.cloud.bbp.common.utils.HttpClientUtil;
import com.gimi.cloud.bbp.commonService.InterfacePlatform.InterfacePlatformRequestService;
import com.gimi.cloud.bbp.commonService.InterfacePlatform.InterfacePlatformTokenService;
import org.apache.http.Header;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class InterfacePlatformRequestServiceImpl implements InterfacePlatformRequestService {
	@Autowired
	InterfacePlatformTokenService tokenService;

	@Override
	public String sendApiPost(String reqData) throws Exception{
		String apiUrl = null;
		try {
			apiUrl = tokenService.getApiUrl();
		} catch (Exception e) {
			throw new MsgException(ResponseCodeEnum.UNKNOWN_ERROR,"获取访问路径异常："+e);
		}
		
		Header[] headers = null;
		try {
			headers = tokenService.getCarryTokenHeader();
		} catch (Exception e) {
			throw new MsgException(ResponseCodeEnum.GET_INTERFACEPLATFORM_TOKEN_HEAD_ERROR,"获取携带TOKEN的请求头异常："+e);
		}
		
		return HttpClientUtil.sendPostJson(apiUrl, reqData, headers);
	}

}
